package com.ny.zmb.openapi.controller;

import com.ny.zmb.openapi.controller.entity.Result;
import com.ny.zmb.openapi.service.PmOrderSplitAccountLogService;
import com.ny.zmb.openapi.ysutil.base.EYinShengBase;
import com.ny.zmb.openapi.ysutil.from.BizReqJsonCollege.BizReqJsonSeparateAccounts;
import com.ny.zmb.openapi.ysutil.utils.RequestNoUntil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 分账2.0.0
 * czz
 */
@RequestMapping("ys/separateAccounts")
@RestController
@CrossOrigin
public class YsSeparateAccountsController extends EYinShengBase {
    @Resource
    private PmOrderSplitAccountLogService pmOrderSplitAccountLogService;

    /**
     * 分账API
     *
     * @param srcMerchantNo 商户号
     * @param obj           请求体
     * @param methodStr     方法
     * @return Result
     */
    @PostMapping("/any/{methodStr}")
    public Result separateAccountsPost(@RequestBody BizReqJsonSeparateAccounts obj, @RequestParam(required = false) String srcMerchantNo, @PathVariable String methodStr) {
        if (obj != null) {
            obj.setRequestNo(obj.getRequestNo() == null ? RequestNoUntil.generateNumericTaskNumber() : obj.getRequestNo());
        }
        return pmOrderSplitAccountLogService.SeparateAccounts(obj, srcMerchantNo, methodStr);
    }

    @PostMapping("divisionRegister")
    public Result divisionRegister(@RequestBody BizReqJsonSeparateAccounts obj, @RequestParam(required = false) String srcMerchantNo) {
        if (obj != null) {
            obj.setRequestNo(obj.getRequestNo() == null ? RequestNoUntil.generateNumericTaskNumber() : obj.getRequestNo());
        }
        return pmOrderSplitAccountLogService.divisionRegister(obj, srcMerchantNo);
    }

    @GetMapping("divisionQuery")
    public Result divisionQuery(@RequestBody BizReqJsonSeparateAccounts obj, @RequestParam(required = false) String srcMerchantNo) {
        if (obj != null) {
            obj.setRequestNo(obj.getRequestNo() == null ? RequestNoUntil.generateNumericTaskNumber() : obj.getRequestNo());
        }
        return pmOrderSplitAccountLogService.divisionQuery(obj, srcMerchantNo);
    }

    @PostMapping("divisionBack")
    public Result divisionBack(@RequestBody BizReqJsonSeparateAccounts obj, @RequestParam(required = false) String srcMerchantNo) {
        if (obj != null) {
            obj.setRequestNo(obj.getRequestNo() == null ? RequestNoUntil.generateNumericTaskNumber() : obj.getRequestNo());
        }
        return pmOrderSplitAccountLogService.divisionBack(obj, srcMerchantNo);
    }

    @PostMapping("divisionBackAuth")
    public Result divisionBackAuth(@RequestBody BizReqJsonSeparateAccounts obj, @RequestParam(required = false) String srcMerchantNo) {
        if (obj != null) {
            obj.setRequestNo(obj.getRequestNo() == null ? RequestNoUntil.generateNumericTaskNumber() : obj.getRequestNo());
        }
        return pmOrderSplitAccountLogService.divisionBackAuth(obj, srcMerchantNo);
    }

    @PostMapping("terminalDivisionRegister")
    public Result terminalDivisionRegister(@RequestBody BizReqJsonSeparateAccounts obj, @RequestParam(required = false) String srcMerchantNo) {
        if (obj != null) {
            obj.setRequestNo(obj.getRequestNo() == null ? RequestNoUntil.generateNumericTaskNumber() : obj.getRequestNo());
        }
        return pmOrderSplitAccountLogService.terminalDivisionRegister(obj, srcMerchantNo);
    }

    @GetMapping("terminalDivisionQuery")
    public Result terminalDivisionQuery(@RequestBody BizReqJsonSeparateAccounts obj, @RequestParam(required = false) String srcMerchantNo) {
        if (obj != null) {
            obj.setRequestNo(obj.getRequestNo() == null ? RequestNoUntil.generateNumericTaskNumber() : obj.getRequestNo());
        }
        return pmOrderSplitAccountLogService.terminalDivisionQuery(obj, srcMerchantNo);
    }


}
